package org.tigris.subversion.svnant.commands;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.ProjectComponent;
import org.tigris.subversion.svnant.SvnFacade;
import org.tigris.subversion.svnant.SvnTask;
import org.tigris.subversion.svnclientadapter.ISVNClientAdapter;
import org.tigris.subversion.svnclientadapter.SVNRevision;

public abstract class SvnCommand extends ProjectComponent
{
  private SvnTask task;
  private ISVNClientAdapter svnClient;

  protected abstract void validateAttributes();

  protected ISVNClientAdapter getClient()
  {
    return this.svnClient;
  }

  public String getCommandname()
  {
    return getClass().getSimpleName();
  }

  public abstract void execute();

  public final void executeCommand(ISVNClientAdapter paramISVNClientAdapter)
    throws BuildException
  {
    this.svnClient = paramISVNClientAdapter;
    verbose("<%s> started ...", new Object[] { getCommandname() });
    try
    {
      validateAttributes();
      execute();
      verbose("<%s> finished.", new Object[] { getCommandname() });
    }
    catch (BuildException localBuildException)
    {
      error("<%s> failed.", new Object[] { getCommandname() });
      throw localBuildException;
    }
    catch (Exception localException)
    {
      error("<%s> failed.", new Object[] { getCommandname() });
      throw new BuildException(localException);
    }
  }

  public SvnTask getTask()
  {
    return this.task;
  }

  public void setTask(SvnTask paramSvnTask)
  {
    this.task = paramSvnTask;
    if (this.task.getProject() != null)
      setProject(this.task.getProject());
  }

  public SVNRevision getRevisionFrom(String paramString)
  {
    try
    {
      return SVNRevision.getRevision(paramString, getDateFormatter());
    }
    catch (ParseException localParseException)
    {
      warning("Unable to parse revision string", new Object[0]);
    }
    return null;
  }

  public String getDateStringFor(Date paramDate)
  {
    return getDateFormatter().format(paramDate);
  }

  private SimpleDateFormat getDateFormatter()
  {
    SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat(SvnFacade.getDateFormatter(this));
    TimeZone localTimeZone = SvnFacade.getDateTimezone(this);
    if (localTimeZone != null)
      localSimpleDateFormat.setTimeZone(localTimeZone);
    return localSimpleDateFormat;
  }

  public void verbose(String paramString, Object[] paramArrayOfObject)
  {
    this.task.verbose(paramString, paramArrayOfObject);
  }

  public void debug(String paramString, Object[] paramArrayOfObject)
  {
    this.task.debug(paramString, paramArrayOfObject);
  }

  public void warning(String paramString, Object[] paramArrayOfObject)
  {
    this.task.warning(paramString, paramArrayOfObject);
  }

  public void info(boolean paramBoolean, String paramString, Object[] paramArrayOfObject)
  {
    this.task.info(paramBoolean, paramString, paramArrayOfObject);
  }

  public void info(String paramString, Object[] paramArrayOfObject)
  {
    this.task.info(paramString, paramArrayOfObject);
  }

  public void error(String paramString, Object[] paramArrayOfObject)
  {
    this.task.error(paramString, paramArrayOfObject);
  }

  public void log(String paramString)
  {
    info(paramString, new Object[0]);
  }

  public void log(String paramString, int paramInt)
  {
    switch (paramInt)
    {
    case 4:
      debug(paramString, new Object[0]);
      break;
    case 0:
      error(paramString, new Object[0]);
      break;
    case 2:
      info(paramString, new Object[0]);
      break;
    case 3:
      verbose(paramString, new Object[0]);
      break;
    case 1:
      warning(paramString, new Object[0]);
    }
  }

  protected static final BuildException ex(String paramString, Object[] paramArrayOfObject)
  {
    return new BuildException(String.format(paramString, paramArrayOfObject));
  }

  protected static final BuildException ex(Exception paramException, String paramString, Object[] paramArrayOfObject)
  {
    return new BuildException(String.format(paramString, paramArrayOfObject), paramException);
  }
}

/* Location:           C:\Users\Administrator\Desktop\svnant.jar
 * Qualified Name:     org.tigris.subversion.svnant.commands.SvnCommand
 * JD-Core Version:    0.6.0
 */